#include <stdio.h>
#include <stdlib.h>
#include <glib.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus.h>
#include <glib-2.0/gobject/gtype.h>

static void bt_manager_changed_cb (DBusGProxy *proxy,
                                   const gchar *state,
                                   gpointer user_data)
{
	printf("state = %s\n",state);
}
 
int main(int argc,char *argv[])
{
	GMainLoop *loop = g_main_loop_new(NULL,TRUE);
	g_type_init();
	GError * error = NULL;
 
	DBusGConnection *gconn = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
	DBusGProxy *m_proxy = dbus_g_proxy_new_for_name(gconn, "com.asianux.btagent","/","com.asianux.btagent.adaptor");
 
	char *str = NULL;
	dbus_g_proxy_call(m_proxy, "test", &error,
			      G_TYPE_INVALID,
				G_TYPE_STRING,&str,
				G_TYPE_INVALID);
 
	dbus_g_proxy_add_signal (m_proxy,
					 "stateChange",
					 G_TYPE_STRING,
					 G_TYPE_INVALID);
			                   
	dbus_g_proxy_connect_signal (m_proxy,              
				           "stateChange",
 					     G_CALLBACK (bt_manager_changed_cb),
					     NULL,
					     NULL);
	printf("str = %s\n",str);
	g_main_loop_run(loop);
 
}
